class Client < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation,:remember_me ,:first_name ,:middle_name , :last_name , :pref_cont_name,:gender,:birthday,:ssn,   :street_address,:mailing_street_address,:phone_number,:pref_contact_medium,:pref_contact_time,:ref_source ,:city,:state,:zip,:mailing_city,:mailing_state,:mailing_zip
  validates_presence_of :first_name
  validates_presence_of :last_name
  validates_presence_of :email
  validates_uniqueness_of :email
  validates_presence_of :gender
  validates_presence_of :birthday
  validates_presence_of :street_address
  validates_presence_of :city
 	validates_presence_of :state
	validates_presence_of :zip
 

CONTACT_TIME = ['Morning','Afternoon','Evening','Late evening','Anytime']
  has_many :authentications,:dependent => :destroy
  belongs_to :employee

  has_many :documents, :through => :client_documents
  has_many :client_documents
  has_one :case
  def apply_omniauth(omniauth,confirmation)
    self.email = omniauth['info']['email'] if email.blank?
    self.first_name = omniauth['info']['first_name'] if first_name.blank?
    self.last_name = omniauth['info']['last_name'] if last_name.blank?
    authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
      if (confirmation) 
      	self.confirmed_at, self.confirmation_sent_at = Time.now  
      end
  end

  def password_required?
    (authentications.empty? || !password.blank?) && super
  end

   def active_for_authentication?
    super && account_active?
   end

  def account_active?
   if self.is_active 
      return true
    else
      return false
    end
  end
  
  def full_name
    return [self.first_name, self.middle_name, self.last_name].join(' ')
  end
  
end


